#include<string>
#include<string.h>
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
    //freopen("in.txt","r",stdin);
    string inp;
    cin>>inp;
    long long ans=0;
    int len=inp.length();
    int cnt=0;
    for(int i=0;i<len;i++){
        if(inp[i]=='T'){cnt++;}
    }
    int pcount=0;
    int tcount=cnt;
    int result=0;
    for(int i=0;i<len;i++){
        if(inp[i]=='P'){pcount++;}
        if(inp[i]=='T'){tcount--;}
        if(inp[i]=='A'){result=result + (pcount * tcount);result=result%1000000007;}
    }

    cout<<result;
}
